package cscie160.hw5;
/**
 * This class implements a minimal wrapper needed to hold the state information
 * that models a bank account.
 * @author Michael Melnikov   
*/
public class Account{
    /**
    * account Id
    */
    int accountNumber;
    
    /**
    * balance on the account
    */
    private int balance;
    
    /**
    * declares the minimal number acceptable as account Id.
    */    
    protected final static int minAccountNumber = 1;    

    /**
    * 1-arg constructor creates account with zero balance
    * @param accountNumber int    
    */   
    public Account(int accountNumber) throws ATMException{
        if (accountNumber < minAccountNumber){
            throw new ATMException("account with ID < " + minAccountNumber + " may not be created");
        }
        this.accountNumber = accountNumber;
        balance = 0;
    }
    
    /**
    * returns account Id
    * @return int
    */   
    public int getAccountId(){
        return accountNumber;
    }
    
    /**
    * deposits sum equal to its argument
    * @param amount int    
    */
    public void deposit(int amount){
        balance += amount;
    }
    
    /**
    * withdraws sum equal to its argument.
    * Throws exception if the funds are insufficient.
    * @param amount int
    */    
    public void withdraw(int amount)  throws ATMException{
        if (amount > balance)
            throw new ATMException(getClass().getName() + ".withdraw: account with ID=" +
                accountNumber + " does not have enough funds.");
        balance -= amount;    
    }    
    
    /**
    * returns balance on the account
    * @return int    
    */
    protected int getBalance(){
        return balance;    
    }
}

